<?php
/*
 * author: Mykolas
 * Pasiima visus pradinius duomenis iš pradinio xls failo ir juos įrašo į duombazę.
 * Apie savo būseną informuoja sėkmės/perspėjimų/klaidų pranešimais
 */

function import_xsl_all($inputFileName, $name) {
    global $subdivisions, $information_systems, $support, $directions, $is__subdivisions, $support_administration, $historical_quantities;
    error_reporting(E_ALL);
    include_once 'import_functions.php';

    $subdivisions = Array();
    $information_systems = Array();
    $support = Array();
    $directions = Array();
    $is__subdivisions = Array();
    $support_administration = Array();
    $historical_quantities = Array();

    date_default_timezone_set('Europe/Vilnius');

    require_once 'Plugins/PhpExcel/PHPExcel/IOFactory.php';


    $objReader = PHPExcel_IOFactory::createReader("Excel5");
    $objReader->setReadDataOnly(true);
    try{
        $objPHPExcel = $objReader->load($inputFileName);
    }
    catch (Exception $e){
        add_error("Nurodytas failas \"".$name."\" yra netinkamo tipo. Apie tai kokius failus leidžiama importuoti galite pasiskaityti pagalbos skiltyje");
        return;
    }

    $processed_sheets = 0;

    if (($sheet = $objPHPExcel->getSheetByName('Padaliniai')) != null) {
        process_subdivision_sheet($sheet);
        save_subdivisions_to_db();
        $processed_sheets++;
    }
    if (($sheet = $objPHPExcel->getSheetByName('IS')) != null) {
        process_is_sheet($sheet);
        save_is_to_db();
        $processed_sheets++;
    }
    if (($sheet = $objPHPExcel->getSheetByName('Paramos priemonės')) != null) {
        process_support_measures($sheet);
        save_support_to_db();
        save_directions_to_db();
        $processed_sheets++;
    }
    if (($sheet = $objPHPExcel->getSheetByName('IS-Padaliniai')) != null) {
        process_is__subdivisions($sheet);
        save_is__subdivisions_to_db();
        $processed_sheets++;
    }
    if (($sheet = $objPHPExcel->getSheetByName('Paramos administravimas')) != null) {
        process_support_administration($sheet);
        save_support_administration_to_db();
        $processed_sheets++;
    }
    if (($sheet = $objPHPExcel->getSheetByName('Paramos kiekiai')) != null) {
        process_support_quantities($sheet);
        save_quantities_to_db();
        $processed_sheets++;
    }

    return $processed_sheets > 0;
}